package com.example.qixin0314.bean;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.qixin0314.Activity.CompanyActivity;
import com.example.qixin0314.R;

import java.util.List;

public class recycleAdapter extends RecyclerView.Adapter<recycleAdapter.myHolder> {
    private List<recycleTextModel>data;
    private Context context;


    public void setData(List<recycleTextModel> data) {
        this.data = data;
    }

    public recycleAdapter(Context context) {
        this.context = context;
    }

    @NonNull
    @Override
    public myHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new myHolder(LayoutInflater.from(context).inflate(R.layout.recycletext_item,null));
    }

    @Override
    public void onBindViewHolder(@NonNull recycleAdapter.myHolder holder, int position) {
        holder.recycleText_text.setText(data.get(position).getName());
        holder.recycleText_text.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(context,CompanyActivity.class);
                intent.putExtra("uri","http://m.qxswt.com/company/"+data.get(position).getId());
                intent.putExtra("name",data.get(position).getName());
                intent.putExtra("puri",data.get(position).getUrl());
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return null!=data?data.size():0;
    }

    class myHolder extends RecyclerView.ViewHolder{
        TextView recycleText_text;

        public myHolder(@NonNull View itemView) {
            super(itemView);
            recycleText_text=itemView.findViewById(R.id.recycleText_text);
        }
    }

}
